package com.imaginaryphysics.www.simpletests;

import com.imaginaryphysics.www.simplepairs.*;

/**
 * 
 *
 */

public class Simple_test {
	
	
	
	public static void main(String[] args) {
		Simple_test test = new Simple_test();	
		test.test_create_SimplePlex();
		test.test_batch_set_calculation();
	}
	
	
	
	SimplePairs<Test> simplePlex;
	int number_of_spoons=3;
	Test[] spoons;
	Pair<?>[] pairs;
	
	public Simple_test(){		
		System.out.println();
		System.out.println("SimplePlex Test");
		System.out.println("Making test objects");
		System.out.println(".............. creating spoons");
		
		
		spoons = new Test[number_of_spoons];
		
		for(int x=0; x<number_of_spoons;x++){
			spoons[x] = new Test(x);
		}

		System.out.println(spoons.length+" spoons created and assigned");

	}
	
	public void test_create_SimplePlex(){
		System.out.println();
		System.out.println("Creating SimplePLex:");
		System.out.println();
		simplePlex = new SimplePairs<Test>(spoons);
		
		System.out.println("Pair array created");
		pairs = simplePlex.get_pairs();
		System.out.println();

		
		for(Pair<?> pair:pairs){
			System.out.println(pair);
			System.out.println("Array Contains pairing");
			System.out.println(pair.get_obj_one());
			System.out.println(pair.get_obj_two());
			System.out.println();
		}
		
		System.out.println("expected number of pairings: "+simplePlex.get_number_of_pairs());
		System.out.println("actual number of pairs: "+pairs.length);

		if(simplePlex.get_number_of_pairs() == pairs.length){
			System.out.println("Pass");
		}
		else{
			System.out.println("Fail");

		}
		
	}

	Result_block[] results;
	My_result[] my_results;
	
	public void test_batch_set_calculation(){
		System.out.println();
		System.out.println("Test batch set relationship:");
		simplePlex.batch_set_relationship("com.imaginaryphysics.www.simpletests.My_calculation","com.imaginaryphysics.www.simpletests.My_result");
		System.out.println("relationship created");
		System.out.println("Running batch calculation");
		simplePlex.batch_calculate();
		System.out.println("Calculation applied");
		System.out.println("Returning Results");
		results =  simplePlex.batch_result();
		System.out.println("Results returned");
		System.out.println("Casting results");
		int number_of_results = results.length;
		my_results = new My_result[number_of_results];
		
		

		for(int x=0;x<number_of_results;x++){
		my_results[x] = (My_result) results[x];
		}
		System.out.println("Results casted");
		System.out.println();
		
		
		System.out.println("Should return");
		System.out.println((spoons[0].x+spoons[1].x));
		System.out.println((spoons[0].x+spoons[2].x));
		System.out.println((spoons[1].x+spoons[2].x));

		
		System.out.println("Returns");
		for(My_result result: my_results){
			System.out.println(result.total_x);
		}
		
	}

	

	

}
